//var _array = require('lodash/array');
var _forEach = require('lodash/foreach');
//var _object = require('lodash/fp/object');

import Feature from 'ol/Feature';

import Point from 'ol/geom/Point';
import VectorSource from 'ol/source/Vector';
import {
  Map,
  View
} from 'ol';
import VectorLayer from 'ol/layer/Vector';
import {
  Vector
} from 'ol/source';
import {
  GeoJSON
} from 'ol/format';
import Overlay from 'ol/Overlay';
import {
  Circle as CircleStyle,
  Fill,
  Stroke,
  Style,
  Text,
  Icon
} from 'ol/style.js';
// import {register} from 'ol/proj/proj4.js';
// import proj4 from 'proj4';
import Projection from 'ol/proj/Projection';
import WMTSTileGrid from 'ol/tilegrid/WMTS';
import TileLayer from 'ol/layer/Tile';
import WMTS from 'ol/source/WMTS';
import ImageLayer from 'ol/layer/Image';
import ImageWMS from 'ol/source/ImageWMS';
import Select from 'ol/interaction/Select.js';
import {
  click
} from 'ol/events/condition.js';
//import {bbox} from 'ol/loadingstrategy';
import {
  defaults as defaultControls,
  Control
} from 'ol/control.js';
import Polygon from 'ol/geom/Polygon';
//import Point from 'ol/geom/Point';
let config = require('../config/config');

function loadWFSLayer(wfsParams) {
  let map = wfsParams.map;
  let layerName = 'temp_wfs_layer';
  if (wfsParams.jsonData.name != undefined && wfsParams.jsonData.name != '') {
    layerName = wfsParams.jsonData.name;
  }
  let vectorSource = new Vector();

  var vector = new VectorLayer({
    source: vectorSource,
    name: layerName,
    zIndex: 14,
    style: wfsParams.styleFunc == null ? wfsParams.style : wfsParams.styleFunc
  });

  var features = new GeoJSON().readFeatures(wfsParams.jsonData);
  vectorSource.addFeatures(features);
  map.addLayer(vector);

  if (wfsParams.selectFunc) {
    // select interaction working on "click"
    var selectClick = new Select({
      condition: click
    });

    selectClick.setProperties({
      name: 'features_select'
    });
    map.addInteraction(selectClick);
    selectClick.on('select', wfsParams.selectFunc);
  }
  return map;
}

function loadOverlay(wfsParams) {
  let map = wfsParams.map;

  _forEach(wfsParams.jsonData.features, function (item) {
    var num = Math.floor(Math.random() * 10 + 2);
    var ele = document.createElement('div');
    ele.className = 'area-box';
    var spannode = document.createElement('span');
    spannode.className = 'dot';
    ele.appendChild(spannode);
    var spannode1 = document.createElement('span');
    spannode1.className = 'pulse delay-' + num;
    ele.appendChild(spannode1);
    var spannode2 = document.createElement('span');
    spannode2.className = 'pulse delay-' + (num - 1);
    ele.appendChild(spannode2);
    var marker = new Overlay({
      position: item.geometry.coordinates,
      positioning: 'center-center',
      element: ele,
      // offset:[0,40],
      stopEvent: true
    });
    map.addOverlay(marker);
  });

  return map;
}

function addMarker(wfsParams) {
  let map = wfsParams.map;
  //添加前先删除已经存在的marker
  let layerLength = map.getLayers().getLength();
  for (let i = 0; i < layerLength; i++) {
    let layer = map.getLayers().item(i);
    if (layer != undefined && layer.getProperties().name == 'popup_marker') {
      map.removeLayer(layer);
      i--;
    }
  }
  //弹出popup
  var overlay = new Overlay({
    element: wfsParams.element,
    autoPan: true,
    autoPanAnimation: {
      duration: 250
    },
    positioning: 'center-center',
  });
  overlay.setProperties({
    name: 'popup_marker'
  });
  map.addOverlay(overlay);
  return map;
}

function showPopUp(params) {

  let map = params.map;
  var marker;
  for (let i = 0; i < map.getOverlays().getLength(); i++) {
    let layer = map.getOverlays().item(i);
    if (layer.getProperties().name == 'popup_marker') {
      marker = layer;
      break;
    }
  }
  if (marker) {
    marker.setPosition(params.coordinate);
  }
}
/**
 * 缩放并设置中心点
 */
function ZoomAndCenter(params) {
  let map = params.map;
  map.getView().setCenter(params.center);
  map.getView().setZoom(params.zoom);
}

function loadRasterLayer(params) {


  let map = params.map;
  let layerName = params.layerName;
  //判断当前图层是否已经加载
  let layerLength = map.getLayers().getLength();
  for (let i = 0; i < layerLength; i++) {
    let layer = map.getLayers().item(i);
    if (layer != undefined && layer.getProperties().name == layerName) {
      map.removeLayer(layer);
      i--;
    }
  }
  var layerSource = new ImageWMS({
    url: config.baseMapUrl + params.mapfile,
    params: {
      'WIDTH': 256,
      'HEIGHT': 256,
      'VERSION': '1.1.1',
      'LAYERS': layerName
    },
    serverType: 'mapserver',
    crossOrigin: 'anonymous'
  });
  var ztLayer = new ImageLayer({
    name: layerName,
    source: layerSource,
    zIndex: 11
  });

  map.addLayer(ztLayer);
  map.getView().setCenter(params.coordinate);
  return map;
}

function loadGeoJsonLayer(mapobj, styleops, geojson) {
  console.log('xxxx');

  let map = null;
  map = mapobj;
  //移除当前图层
  let layerLength = map.getLayers().getLength();
  for (let i = 0; i < layerLength; i++) {
    let layer = map.getLayers().item(i);
    if (layer != undefined && layer.getProperties().name == 'temp_geojsonLayer') {
      map.removeLayer(layer);
      i--;
    }
  }
  var geoSource = new Vector({
    features: (new GeoJSON()).readFeatures(geojson)
  });

  var styles = getGeoJsonStyle(styleops);

  var geoLayer = new VectorLayer({
    name: 'temp_geojsonLayer',
    source: geoSource,
    zIndex: 13,
    style: styles
  });
  map.addLayer(geoLayer);

  return map;
}

function loadGeoJsonLayerNew(geoJsonParams) {
  let map = null;
  map = geoJsonParams.map;
  let layerName = 'temp_geoJson_layer';
  if (geoJsonParams.jsonData.name != undefined && geoJsonParams.jsonData.name != '') {
    layerName = geoJsonParams.jsonData.name;
  }
  //如果存在同名图层，删除
  let layerLength = map.getLayers().getLength();
  for (let i = 0; i < layerLength; i++) {
    let layer = map.getLayers().item(i);
    if (layer != undefined && layer.getProperties().name == layerName) {
      map.removeLayer(layer);
      i--;
    }
  }

  var geoSource = new Vector({
    features: (new GeoJSON()).readFeatures(geoJsonParams.jsonData)
  });

  var geoLayer = new VectorLayer({
    name: layerName,
    source: geoSource,
    visible: geoJsonParams.visible,
    zIndex: geoJsonParams.zIndex,
    style: geoJsonParams.styleFunc == null ? geoJsonParams.style : geoJsonParams.styleFunc
  });
  map.addLayer(geoLayer);

  return map;
}

function initBlankMap(divID) {
  let map = null;

  let wmsSource = new ImageWMS({
    url: config.baseMapUrl + 'wuhai-blankmap',
    params: {
      'FORMAT': 'image/png',
      'VERSION': '1.1.1',
      'WIDTH': 256,
      'HEIGHT': 256,
      'LAYERS': 'background,river,road,roadp,house,Railway,village,Government,Hospital' //,80Worklimitl,gsj1,nmjs,qxj,msm,qxm,sxm,sxx,tl,sjysgl,mzfzd,zrc'
    },
    serverType: 'mapserver',
    crossOrigin: 'anonymous'
  });
  let wmsLayer = new ImageLayer({
    name: 'base_vect_Layer',
    source: wmsSource,
    visible: true,
    zIndex: 9
  });
  let xzqSource = new ImageWMS({
    url: config.baseMapUrl + 'wuhai-blankmap',
    params: {
      'FORMAT': 'image/png',
      'VERSION': '1.1.1',
      'WIDTH': 256,
      'HEIGHT': 256,
      'LAYERS': 'xzqjx,xzqjx1,xzqname' //,xzqjx1,gsj1,nmjs,qxj,msm,qxm,sxm,sxx,tl,sjysgl,mzfzd,zrc'
    },
    serverType: 'mapserver',
    crossOrigin: 'anonymous'
  });
  let xzqjxLayer = new ImageLayer({
    name: 'base_Layer2',
    source: xzqSource,
    zIndex: 20
  });

  var bounds = [36193299.9058757, 4279101.15693256, 36586533.1437, 4515833.68722927];
  var resolutions = [1536.06719, 768.033595, 384.016798, 192.008399, 96.0041994, 48.0020997, 24.0010498, 12.0005249, 6.00026246, 3.00013123, 1.50006562, 0.75003281, 0.3750164, 0.1875082, 0.0937541, 0.04687705];
  //var matrixIds = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
  let projection = new Projection({
    code: 'EPSG:2360'
  });

  // var tileGrid = new WMTSTileGrid({
  //   origin: [bounds[0], bounds[3]],
  //   resolutions: resolutions,
  //   matrixIds: matrixIds,
  //   sizes: [256, 256],
  //   extent: bounds
  // });

  //创建地图
  map = new Map({

    view: new View({
      center: [(bounds[2] + bounds[0]) / 2, (bounds[3] + bounds[1]) / 2 - 30000],
      projection: projection,
      resolution: resolutions[3],
      resolutions: resolutions,
      minZoom: 2
    }),
    layers: [
      xzqjxLayer,
      wmsLayer, //xzqjxLayer
    ],
    //将地图添加到的map容器中
    target: divID
  });


  return map;
}

function initMap(divID) {

  //创建一个控件
  var SwitchLayerControl = (function (Control) {
    function SwitchLayerControl(opt_options) {

      var options = opt_options || {};
      var topelement = document.createElement('div');
      topelement.className = 'toggle btn-group m-b';
      var button1 = document.createElement('button');
      button1.id = 'base_satellite_Layer_btn';
      button1.className = 'btn btn-stroke btn-info';
      button1.type = 'button';
      button1.innerHTML = '矢量';
      var button2 = document.createElement('button');
      button2.id = 'base_vect_Layer_btn';
      button2.className = 'btn btn-stroke btn-info';
      button2.type = 'button';
      button2.innerHTML = '卫星';
      topelement.appendChild(button1);
      topelement.appendChild(button2);
      Control.call(this, {
        element: topelement,
        target: options.target
      });
      button1.addEventListener('click', this.handleRotateNorth1.bind(this), false);
      button2.addEventListener('click', this.handleRotateNorth2.bind(this), false);
      button1.focus();
    }

    if (Control) SwitchLayerControl.__proto__ = Control;
    SwitchLayerControl.prototype = Object.create(Control && Control.prototype);
    SwitchLayerControl.prototype.constructor = SwitchLayerControl;

    SwitchLayerControl.prototype.handleRotateNorth1 = function handleRotateNorth1() {
      this.getMap().getLayers().forEach(function (layer) {
        if (layer.getProperties().name != undefined && layer.getProperties().name == 'base_satellite_Layer') {
          layer.setVisible(false);
        }
        if (layer.getProperties().name != undefined && layer.getProperties().name == 'base_vect_Layer') {
          layer.setVisible(true);
        }
      });
    };
    SwitchLayerControl.prototype.handleRotateNorth2 = function handleRotateNorth2() {
      this.getMap().getLayers().forEach(function (layer) {
        if (layer.getProperties().name != undefined && layer.getProperties().name == 'base_satellite_Layer') {
          layer.setVisible(true);
        }
        if (layer.getProperties().name != undefined && layer.getProperties().name == 'base_vect_Layer') {
          layer.setVisible(false);
        }
      });
    };
    return SwitchLayerControl;
  }(Control));

  //创建一个控件
  var ResizeMapControl = (function (Control) {
    function ResizeMapControl(opt_options) {

      var options = opt_options || {};
      var button = document.createElement('button');
      var iTag = document.createElement('i');
      iTag.className = 'fa fa-home';
      button.appendChild(iTag);

      var element = document.createElement('div');
      element.className = 'rotate-north ol-unselectable ol-control';
      element.appendChild(button);

      Control.call(this, {
        element: element,
        target: options.target
      });
      button.addEventListener('click', this.resizeMap.bind(this), false);
    }

    if (Control) ResizeMapControl.__proto__ = Control;
    ResizeMapControl.prototype = Object.create(Control && Control.prototype);
    ResizeMapControl.prototype.constructor = ResizeMapControl;

    ResizeMapControl.prototype.resizeMap = function resizeMap() {
      let bounds = [36193299.9058757, 4279101.15693256, 36586533.1437, 4515833.68722927];
      this.getMap().getView().setCenter([(bounds[2] + bounds[0]) / 2, (bounds[3] + bounds[1]) / 2 - 30000]);
      this.getMap().getView().setResolution(192.008399);
    };
    return ResizeMapControl;
  }(Control));

  let map = null;

  let wmsSource = new ImageWMS({
    url: config.baseMapUrl + 'wuhai-basemap',
    params: {
      'FORMAT': 'image/png',
      'VERSION': '1.1.1',
      'WIDTH': 256,
      'HEIGHT': 256,
      'LAYERS': 'background,river,road,roadp,house,Railway,village,Government,Hospital' //,80Worklimitlgsj1,nmjs,qxj,msm,qxm,sxm,sxx,tl,sjysgl,mzfzd,zrc'
    },
    serverType: 'mapserver',
    crossOrigin: 'anonymous'
  });
  let wmsLayer = new ImageLayer({
    name: 'base_vect_Layer',
    source: wmsSource,
    visible: false,
    zIndex: 9
  });
  let xzqSource = new ImageWMS({
    url: config.baseMapUrl + 'wuhai-basemap',
    params: {
      'FORMAT': 'image/png',
      'VERSION': '1.1.1',
      'WIDTH': 256,
      'HEIGHT': 256,
      'LAYERS': 'xzqjx,xzqjx1,xzqname' //,gsj1,nmjs,qxj,msm,qxm,sxm,sxx,tl,sjysgl,mzfzd,zrc'
    },
    serverType: 'mapserver',
    crossOrigin: 'anonymous'
  });
  let xzqjxLayer = new ImageLayer({
    name: 'base_Layer2',
    source: xzqSource,
    zIndex: 20
  });

  var bounds = [36193299.9058757, 4279101.15693256, 36586533.1437, 4515833.68722927];
  var resolutions = [1536.06719, 768.033595, 384.016798, 192.008399, 96.0041994, 48.0020997, 24.0010498, 12.0005249, 6.00026246, 3.00013123, 1.50006562, 0.75003281, 0.3750164, 0.1875082, 0.0937541, 0.04687705];
  var matrixIds = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
  let projection = new Projection({
    code: 'EPSG:2360'
  });

  var tileGrid = new WMTSTileGrid({
    origin: [bounds[0], bounds[3]],
    resolutions: resolutions,
    matrixIds: matrixIds,
    sizes: [256, 256],
    extent: bounds
  });

  var wmtsImgSource = new WMTS({
    url: config.baseImgMapUrl,
    layer: 'whimg',
    format: 'image/png',
    matrixSet: 'Xian8036',
    projection: projection,
    tileGrid: tileGrid
  });
  let wmtsSatelliteLayer = new TileLayer({
    name: 'base_satellite_Layer',
    source: wmtsImgSource,
    visible: true
  });

  //创建地图
  map = new Map({
    controls: defaultControls().extend([
      new ResizeMapControl(),
      new SwitchLayerControl()
    ]),
    view: new View({
      center: [(bounds[2] + bounds[0]) / 2, (bounds[3] + bounds[1]) / 2 - 30000],
      projection: projection,
      resolution: resolutions[3],
      resolutions: resolutions,
      minZoom: 3
    }),
    layers: [
      wmsLayer, xzqjxLayer,
      wmtsSatelliteLayer
    ],
    //将地图添加到的map容器中
    target: divID
  });


  return map;
}

function removeAllLayers(mapobj) {
  let map = mapobj;
  let layerLength = map.getLayers().getLength();
  for (let i = 0; i < layerLength; i++) {
    let layer = map.getLayers().item(i);
    if (layer != undefined && layer.getProperties().name.indexOf('base_') < 0) {
      map.removeLayer(layer);
      i--;
    }
  }
  return map;
}

function removeInteractions(mapobj) {
  let map = mapobj;
  let iLength = map.getInteractions().getLength();
  for (let i = 0; i < iLength; i++) {
    let interaction = map.getInteractions().item(i);
    if (interaction instanceof Select) {

      if (interaction.getProperties().name == 'features_select') {

        map.removeInteraction(interaction);
        i--;
      }
    }

  }
  return map;
}

function removeAllOverlay(mapobj) {
  let map = mapobj;

  for (let i = 0; i < map.getOverlays().getLength(); i++) {
    let layer = map.getOverlays().item(i);
    map.removeOverlay(layer);
    i--;
  }
  return map;
}

function getPixFromCoordinate(map, lng, lat) {

  let smap = map;
  return smap.getPixelFromCoordinate([lng, lat]);
}

function loadHightLightLayer(mapobj, styleops, geojson) {

  let map = null;
  map = mapobj;
  //移除当前图层
  let layerLength = map.getLayers().getLength();
  for (let i = 0; i < layerLength; i++) {
    let layer = map.getLayers().item(i);
    if (layer != undefined && layer.getProperties().name == 'temp_hightlightLayer') {
      map.removeLayer(layer);
      i--;
    }
  }
  var geoSource = new Vector({
    features: (new GeoJSON()).readFeatures(geojson)
  });

  var styles = getGeoJsonStyle(styleops);

  var geoLayer = new VectorLayer({
    name: 'temp_hightlightLayer',
    source: geoSource,
    zIndex: 21,
    style: styles
  });
  map.addLayer(geoLayer);
  //map.getView().fit( geoSource.getExtent());
  return map;
}
//获取多边形内点
function getPolygonExtents(polyCoords) {
  // let features=(new GeoJSON()).readFeatures(geojson);
  // let geome=features[0].getGeometry();
  // console.log(geome);
  let geom = new Polygon(polyCoords);
  return geom.getExtent();
  //return geom.getInteriorPoint();
}

function drawFeaturesAndZoom(wfsParams) {
  let map = wfsParams.map;
  //移除当前图层
  let layerLength = map.getLayers().getLength();
  for (let i = 0; i < layerLength; i++) {
    let layer = map.getLayers().item(i);
    if (layer != undefined && layer.getProperties().name == 'temp_vect_layer') {
      map.removeLayer(layer);
      i--;
    }
  }
  var startMarker = new Feature({
    type: 'icon',
    geometry: new Point(wfsParams.center)
  });
  var styles = getGeoJsonStyle('markerPoint');
  var vectorLayer = new VectorLayer({
    name: 'temp_vect_layer',
    source: new VectorSource({
      features: [startMarker]
    }),
    zIndex: 25,
    style: styles
  });
  map.addLayer(vectorLayer);
  map.getView().setCenter(wfsParams.center);
  map.getView().setZoom(wfsParams.zoom);
  return map;

}

function getGeoJsonStyle(styleName) {
  let resStyle = null;

  switch (styleName) {
  case 'qyjcd':
    resStyle = new Style({
      image: new CircleStyle({
        radius: 2,
        fill: null,
        stroke: new Stroke({
          color: 'red',
          width: 1
        })
      }),
      fill: new Fill({
        color: 'rgba(255, 255, 255, 0.6)'
      }),
      stroke: new Stroke({
        color: '#319FD3',
        width: 1
      }),
      text: new Text({
        font: '12px Calibri,sans-serif',
        fill: new Fill({
          color: '#363642'
        }),
        stroke: new Stroke({
          color: '#363642',
          width: 1
        })
      })
    });
    break;
  case 'mine':
    resStyle = new Style({
      stroke: new Stroke({
        //color: 'rgb(123, 196, 241)',
        color: '#934b34',
        width: 1
      }),
      fill: new Fill({
        color: '#934b3490'
      })
    });
    break;
  case 'mine30':
    resStyle = new Style({
      stroke: new Stroke({
        //color: 'rgb(123, 196, 241)',
        color: 'rgb(130, 104, 87)',
        width: 1
      }),
      fill: new Fill({
        color: 'rgb(255, 17, 68)'
      })
    });
    break;
  case 'Chimney':
    resStyle = new Style({
      image: new CircleStyle({
        radius: 2,
        fill: null,
        stroke: new Stroke({
          color: 'red',
          width: 1
        })
      }),
      fill: new Fill({
        color: 'rgba(255, 255, 255, 0.6)'
      }),
      stroke: new Stroke({
        color: '#319FD3',
        width: 1
      }),
      text: new Text({
        font: '12px Calibri,sans-serif',
        fill: new Fill({
          color: '#363642'
        }),
        stroke: new Stroke({
          color: '#363642',
          width: 1
        })
      })
    });
    break;
  case 'highlightmine':
    resStyle = new Style({
      stroke: new Stroke({
        //color: 'rgb(123, 196, 241)',
        color: '#fb4007',
        width: 1
      }),
      fill: new Fill({
        color: '#fb400750'
      })
    });
    break;
  case 'CoalGanguehill':
    resStyle = new Style({
      stroke: new Stroke({
        //color: 'rgb(123, 196, 241)',
        color: '#fdba78',
        width: 1
      }),
      fill: new Fill({
        color: '#d6d9f8a0'
      })
    });
    break;
  case 'landuse':
    resStyle = {
      '01': new Style({
        stroke: new Stroke({
          color: 'rgb(0, 160, 100)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(255, 255, 100)'
        })
      }),
      '02': new Style({
        stroke: new Stroke({
          color: 'rgb(0,165,60)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(255, 200, 80)'
        })
      }),
      '03': new Style({
        stroke: new Stroke({
          color: 'rgb(0,0,0)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(40, 140, 0)'
        })
      }),
      '04': new Style({
        stroke: new Stroke({
          color: 'rgb(0,135,80)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(150, 210, 50)'
        })
      }),
      '10': new Style({
        stroke: new Stroke({
          color: 'rgb(0,0,0)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(175, 85, 80)'
        })
      }),
      '11': new Style({
        stroke: new Stroke({
          color: 'rgb(180,220,250)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(160, 205, 240)'
        })
      }),
      '12': new Style({
        stroke: new Stroke({
          color: 'rgb(0,140,80)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(200, 205, 200)'
        })
      }),
      '20': new Style({
        stroke: new Stroke({
          color: 'rgb(0,0,0)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(230, 120, 130)'
        })
      }),
    };
    break;
  case 'lstnetfish':
    resStyle = {
      'lv0': new Style({
        stroke: new Stroke({
          color: 'rgb(0, 160, 100)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(93, 25, 206)'
        })
      }),
      'lv1': new Style({
        stroke: new Stroke({
          color: 'rgb(0, 160, 100)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(1, 28, 250)'
        })
      }),
      'lv2': new Style({
        stroke: new Stroke({
          color: 'rgb(0,165,60)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(1, 28, 250)'
        })
      }),
      'lv3': new Style({
        stroke: new Stroke({
          color: 'rgb(0,0,0)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(53, 169, 62)'
        })
      }),
      'lv4': new Style({
        stroke: new Stroke({
          color: 'rgb(0,135,80)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(53, 169, 62)'
        })
      }),
      'lv5': new Style({
        stroke: new Stroke({
          color: 'rgb(0,0,0)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(239, 131, 32)'
        })
      }),
      'lv6': new Style({
        stroke: new Stroke({
          color: 'rgb(180,220,250)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(239, 131, 32)'
        })
      }),
      'lv7': new Style({
        stroke: new Stroke({
          color: 'rgb(0,140,80)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(254, 0, 2)'
        })
      }),
      'lv8': new Style({
        stroke: new Stroke({
          color: 'rgb(0,0,0)',
          width: 1
        }),
        fill: new Fill({
          color: 'rgb(254, 0, 2)'
        })
      }),
    };
    break;
  case 'markerPoint':
    resStyle = new Style({
      image: new Icon({
        anchor: [0, 1],
        //imgSize: [16, 16],
        size: [32, 32],
        src: 'http://localhost/gpsbz_16.png'
      })
    });
    break;
  case 'pm25style':
    resStyle = {
      'lv1': new Style({
        stroke: new Stroke({
          color: '#096',
          width: 1
        }),
        fill: new Fill({
          color: '#096'
        })
      }),
      'lv2': new Style({
        stroke: new Stroke({
          color: '#ffde33',
          width: 1
        }),
        fill: new Fill({
          color: '#ffde33'
        })
      }),
      'lv3': new Style({
        stroke: new Stroke({
          color: '#ff9933',
          width: 1
        }),
        fill: new Fill({
          color: '#ff9933'
        })
      }),
      'lv4': new Style({
        stroke: new Stroke({
          color: '#cc0033',
          width: 1
        }),
        fill: new Fill({
          color: '#cc0033'
        })
      }),
      'lv5': new Style({
        stroke: new Stroke({
          color: '#660099',
          width: 1
        }),
        fill: new Fill({
          color: '#660099'
        })
      }),
      'lv6': new Style({
        stroke: new Stroke({
          color: '#7e0023',
          width: 1
        }),
        fill: new Fill({
          color: '#7e0023'
        })
      }),

    };
    break;
  default:
    resStyle = new Style({
      stroke: new Stroke({
        //color: 'rgb(123, 196, 241)',
        color: 'rgb(130, 104, 87)',
        width: 1
      }),
      fill: new Fill({
        color: 'rgb(255, 17, 68)'
      })
    });

  }
  return resStyle;
}
export {
  initMap,
  initBlankMap,
  loadWFSLayer,
  loadRasterLayer,
  loadOverlay,
  addMarker,
  ZoomAndCenter,
  loadGeoJsonLayer,
  getGeoJsonStyle,
  removeAllLayers,
  removeAllOverlay,
  removeInteractions,
  showPopUp,
  getPixFromCoordinate,
  loadHightLightLayer,
  getPolygonExtents,
  drawFeaturesAndZoom,
  loadGeoJsonLayerNew
};
